Skip to content

Conversation

@ElliottjPierce
Copy link

Objective

Bevy is considering not allowing mutable world access in WorldQuery::init_state.
See here.
This PR explores how this crate might migrate if those changes go through.

Solution

Don't initialize the registry resource in init_state.
Use atomics to seal the registry.

There is one caveat.
Before this pr, if a component was registered for a trait after the query was made, it would panic.
After this pr, that panic will only happen if, when the query was made, there were already components registered for that trait.

Situation previous behavior new behavior
All components registered before first query Works as expected Works as expected
Some components registered before first query and some after Panics on late registration Panics on late registration
No components are registered Warns Warns
No components are registered before a query is made, but then some are registered Warns and panics Just warns

Since both the warning and panic serve the same purpose (to remind users to actually register their components), I don't think this is a concern, but I wanted to be transparent about it.

@ElliottjPierce ElliottjPierce marked this pull request as draft January 26, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant